/*
 * @Author: your name
 * @Date: 2022-02-10 16:58:54
 * @LastEditTime: 2022-02-10 17:04:39
 * @LastEditors: Please set LastEditors
 * @Description: 封装AuthRouter
 * @FilePath: \jike\src\components\AuthRouter.js
 */
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { hasToken } from 'utils/storage';
function AuthRouter({ component: Component, ...rest }) {
  return (
    <Route
      {...rest}
      render={(props) => {
        // console.log("props", props)
        if (hasToken()) {
          return <Component {...props}></Component>;
        } else {
          return (
            <Redirect
              to={{ pathname: '/login', state: { from: props.location } }}
            ></Redirect>
          );
        }
      }}
    ></Route>
  );
}

export default AuthRouter;
